﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace helpcarla
{
    public partial class frmViewMedicalInfo : Form
    {
        public frmViewMedicalInfo()
        {
            InitializeComponent();
        }

        private void frmViewMedicalInfo_Load(object sender, EventArgs e)
        {
            frmMain.connectDB().Open();
            string selectQuery = "SELECT Date FROM DailyFoodLog UNION ALL SELECT Date FROM Moods";
            DataSet ds = new DataSet();
            MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter(selectQuery, frmMain.connectDB());
            da.Fill(ds);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                lstDates.Items.Add(dr["Date"].ToString());
                lstDates.Sorted = true;
            }
            if (ds.Tables[0].Rows.Count < 1)
            {
                MessageBox.Show("There are no dates in the database");
                this.Close();
            }
            frmMain.disconnectDB();
        }

        private void lstDates_SelectedValueChanged(object sender, EventArgs e)
        {
            frmMain.connectDB();
            lblDate.Text = lstDates.SelectedItem.ToString();

            string selectBreakfastQuery = "SELECT Food, Drink FROM DailyFoodLog WHERE Meal = Breakfast AND Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dab = new MySql.Data.MySqlClient.MySqlDataAdapter(selectBreakfastQuery, frmMain.connectDB());
            txtDinner.Text = dab.ToString();

            string selectBreakfastTimeQuery = "SELECT FoodTime FROM DailyFoodLog WHERE Meal = Breakfast AND Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dabt = new MySql.Data.MySqlClient.MySqlDataAdapter(selectBreakfastTimeQuery, frmMain.connectDB());
            txtDinnerTime.Text = dabt.ToString();

            string selectLunchQuery = "SELECT Food, Drink FROM DailyFoodLog WHERE Meal = Lunch AND Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dal = new MySql.Data.MySqlClient.MySqlDataAdapter(selectLunchQuery, frmMain.connectDB());
            txtDinner.Text = dal.ToString();

            string selectLunchTimeQuery = "SELECT FoodTime FROM DailyFoodLog WHERE Meal = Lunch AND Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dalt = new MySql.Data.MySqlClient.MySqlDataAdapter(selectLunchTimeQuery, frmMain.connectDB());
            txtDinnerTime.Text = dalt.ToString();

            string selectDinnerQuery = "SELECT Food, Drink FROM DailyFoodLog WHERE Meal = Dinner AND Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dad = new MySql.Data.MySqlClient.MySqlDataAdapter(selectDinnerQuery, frmMain.connectDB());
            txtDinner.Text = dad.ToString();

            string selectDinnerTimeQuery = "SELECT FoodTime FROM DailyFoodLog WHERE Meal = Dinner AND Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dadt = new MySql.Data.MySqlClient.MySqlDataAdapter(selectDinnerTimeQuery, frmMain.connectDB());
            txtDinnerTime.Text = dadt.ToString();

            string selectMedicineQuery = "SELECT Medicine FROM DailyFoodLog WHERE Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dam = new MySql.Data.MySqlClient.MySqlDataAdapter(selectMedicineQuery, frmMain.connectDB());
            txtMedicine.Text = dam.ToString();

            string selectMedicineTimeQuery = "SELECT MedicineTime FROM DailyFoodLog WHERE Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter damt = new MySql.Data.MySqlClient.MySqlDataAdapter(selectMedicineTimeQuery, frmMain.connectDB());
            txtMedicineTime.Text = damt.ToString();

            string selectEnergyQuery = "SELECT EnergyLevel FROM EmotionalLevels WHERE Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dae = new MySql.Data.MySqlClient.MySqlDataAdapter(selectEnergyQuery, frmMain.connectDB());
            txtEnergyRating.Text = dae.ToString();

            string selectPainQuery = "SELECT PainLevel FROM EmotionalLevels WHERE Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter dap = new MySql.Data.MySqlClient.MySqlDataAdapter(selectPainQuery, frmMain.connectDB());
            txtPainRating.Text = dap.ToString();

            string selectWokeUpQuery = "SELECT WokeUpTime FROM SleepHabits WHERE Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter daw = new MySql.Data.MySqlClient.MySqlDataAdapter(selectWokeUpQuery, frmMain.connectDB());
            txtWokeUp.Text = daw.ToString();

            string selectFellAsleepQuery = "SELECT FellAsleepTime FROM SleepHabits WHERE Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter daf = new MySql.Data.MySqlClient.MySqlDataAdapter(selectFellAsleepQuery, frmMain.connectDB());
            txtFellAsleep.Text = daf.ToString();

            string selectMoodQuery = "SELECT MoodDescription FROM Moods WHERE Date = " + lstDates.SelectedItem.ToString();
            MySql.Data.MySqlClient.MySqlDataAdapter damd = new MySql.Data.MySqlClient.MySqlDataAdapter(selectMoodQuery, frmMain.connectDB());
            txtMood.Text = damd.ToString();
            frmMain.disconnectDB();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
